//
//  HRAppDelegate.m
//  HR_Touch
//
//  Created by 2365272230@qq.com on 07/24/2017.
//  Copyright (c) 2017 2365272230@qq.com. All rights reserved.
//

#import "HRAppDelegate.h"
#import "HRTouchManager.h"
#import "HR_Touch_TestViewController.h"
#import "HR_Touch_HomeViewController.h"

@interface HRAppDelegate ()<
    HRTouchManagerDelegate,
    HRTouchManagerDataSource
    >
@property (nonatomic,strong) NSArray *itemTitleArr;
@property (nonatomic,strong) NSArray *itemIconArr;
@property (nonatomic,strong) HRTouchManager * touchManager;

@end

@implementation HRAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    self.window.backgroundColor=[UIColor whiteColor];
    self.window.rootViewController=[[UINavigationController alloc]initWithRootViewController:[[HR_Touch_HomeViewController alloc] init]];
    [self.window makeKeyAndVisible];
    [self configTouchData];
    [self configNotiWithApplication:application];
    
    return YES;
}

- (void)configTouchData{
//    HRTouchManager * touchManager = [HRTouchManager sharedManager];
//    touchManager.titleArr = @[@"商品",@"相机",@"订单"];
//    touchManager.iconArr = @[@"icon_shortcut_scan",@"icon_shortcut_search",@"icon_shortcut_order1"];
    
    self.itemTitleArr = @[@"商品",@"相机",@"订单"];
    self.itemIconArr = @[@"icon_shortcut_scan",@"icon_shortcut_search",@"icon_shortcut_order1"];
    
    HRTouchManager * manager = [[HRTouchManager alloc] initWithDataSource:self andDelegate:self];
    self.touchManager = manager;
}
#pragma mark --------------HRTouchManager的数据源和代理--------------

- (NSInteger)hr_numberOfItemsInTouch:(HRTouchManager *)manager{
    return self.itemTitleArr.count;
}

//文字数组
- (NSArray *)hr_itemTitlesForInTouch:(HRTouchManager *)manager{
    return self.itemTitleArr;
}

////自定义图片数组
//- (NSArray *)hr_itemIconsForCustomInTouch:(HRTouchManager *)manager{
//    return self.itemIconArr;
//}

//使用系统图片
- (NSArray *)hr_itemIconsForSystemType:(UIApplicationShortcutIconType)iconType InTouch:(HRTouchManager *)manager{
    return @[@(UIApplicationShortcutIconTypeSearch),@(UIApplicationShortcutIconTypeShare),@(UIApplicationShortcutIconTypeContact)];
}

#pragma mark --------------HRTouchManager的代理--------------
- (void)manager:(HRTouchManager *)manager hr_didSelectItemRowAtIndex:(NSInteger)index{
    
    if (index == 0) {
        [manager openSystemFunctionItem:HRFunctionItemCamera];
    }else if (index == 1){
        [manager openSettingItem:HRSettingsGeneral];
    }else{
    
        HR_Touch_TestViewController * testVC  = [[HR_Touch_TestViewController alloc ] init];
        testVC.index = index;
        UINavigationController * navVC = (UINavigationController *)self.window.rootViewController;
        [navVC pushViewController:testVC animated:YES];
    }
}

- (void)configNotiWithApplication:(UIApplication *)application{
    // 请求获取DeviceToken
    if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
        // 1.获取发送通知的权限
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [application registerUserNotificationSettings:settings];
        
        // 2.注册远程通知
        [application registerForRemoteNotifications];
    } else {
        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
    }
}

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
    [self.touchManager clickWithShortcutItem:shortcutItem];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    // 跳转到固定的界面
    if (application.applicationState == UIApplicationStateInactive) {
        // 进行页面的跳转
    } else {
        // 其他情况不需要跳转
    }
}



- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
